import { createStore } from "redux";
import DragDropManagerImpl from "./classes/DragDropManagerImpl";
import DragDropMonitor from "./classes/DragDropMonitor";
import reducer from "./reducer";

/**
 * 创建拖拽管理器的工具
 * 它管理着整个拖拽系统
 * 整个Dnd应用的状态会放在redux的仓库的store
 */
function createDragDropManager(backendFactory) {
  //创建一个仓库存放Dnd项目的状态或者说数据
  const store = createStore(reducer);
  const globalMonitor = new DragDropMonitor(store);
  const manager = new DragDropManagerImpl(store, globalMonitor);
  let backend = backendFactory(manager);
  manager.receiveBackend(backend);
  return manager;
}
export default createDragDropManager;
